import React, { Component } from 'react'
import { Route, Switch, Redirect } from 'react-router-dom'
import Login from 'pages/Login/index.js'
import NotFound from 'pages/NotFound/index.js'
import Admin from 'pages/Admin/index.js'
import { Suspense } from 'react'
import 'antd/dist/antd.css'
import { Spin } from 'antd'
export default class App extends Component {
  render() {
    return (
    <Suspense  fallback={<Spin size="large"/>}>
      <Switch>
         <Route
            path="/login"
            component={Login}
         />
         <Route
            path="/404"
            component={NotFound}
         />
         <Route
            path="/admin"
            render={(routeProps)=>{
              // 登录鉴权
              const token = localStorage.getItem('token')
              if(token){
                return <Admin {...routeProps}/>
              }else{
                return <Redirect to="/login"/>
              }
            }}
         />
         <Redirect to="/admin" from="/" exact/>
         <Redirect to="/404"/>
      </Switch>
     </Suspense>
    )
  }
}
